import { WarehouseService } from './../../../settings/services/warehouse.service';
import { Component, OnInit, Injector } from '@angular/core';
import { ListBase } from 'app/modules/base/list-base';
import { map } from 'rxjs/operators';
import * as _ from 'lodash';

@Component({
  selector: 'm-list',
  templateUrl: './list.component.html',
  styleUrls: ['./list.component.scss'],
})
export class ListComponent extends ListBase implements OnInit {
  appStoreAdminUrl: string;
  constructor(
    private injector: Injector,
    private warehouseService: WarehouseService,
  ) {
    super(injector);
  }
  result$ = this.route.data.pipe(
    map((data) => {
      data.list.list.map((item) => {
        item['pk'] = `${item.id}-${item.area_id}`;
        return item;
      });
      return data.list;
    }),
  );

  Sortable = ['id', 'name', 'upgrade_at', 'update_admin_username', 'updated_at', 'created_at'];
  async ngOnInit() {
    const resp = await this.warehouseService.getAppStoreConfigWithKey('DeepinAppStoreBackgroundUrl');
    this.appStoreAdminUrl = resp.message;
  }

  goToAdminUrl() {
    window.open(
      this.appStoreAdminUrl,
      '_blank'
    );
  }
}
